<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        let arr = [
            { id: 1, name: '部门1', pid: 0 },
            { id: 2, name: '部门2', pid: 1 },
            { id: 3, name: '部门3', pid: 1 },
            { id: 4, name: '部门4', pid: 3 },
            { id: 5, name: '部门5', pid: 4 },
        ]
        function transformToTree(arr,num = 0){
            
        }


const result = [{0:[{ id: 1, name: '部门1', pid: 0,chlidren:{1:[{ id: 2, name: '部门2', pid: 1 },  { id: 3, name: '部门3', pid: 1 ,chlidren:[{3:{ id: 4, name: '部门4', pid: 3,chlidren:[{4: { id: 5, name: '部门5', pid: 4 }}] },}]}]} }]}]

// 算法，人能写出来  再翻译成计算机可执行的语句



// 1.创建
/*
const result = [{0:[]}]
const result = [{0:{}]



*/




    </script>
</body>

</html>